{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cef7fbcf-dcc4-4986-998f-5bd6c058b348",
   "metadata": {},
   "source": [
    "# An Example of Searchain Application"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae02aac8-ddc3-481f-9b41-a3c52f2ad9b5",
   "metadata": {},
   "source": [
    "This LlamaPack implements short form the [SearChain paper by Xu et al..](https://arxiv.org/abs/2304.14732)\n",
    "\n",
    "This implementation is adapted from the author's implementation. You can find the official code repository [here](https://github.com/xsc1234/Search-in-the-Chain)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d500e8af-c685-4f11-b176-dd534c7824e5",
   "metadata": {},
   "source": [
    "## Load Pack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "pqRveoDVZepc",
   "metadata": {},
   "outputs": [],
   "source": [
    "! pip install llama-index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a111a49c-e9c2-4a19-96dc-136fc820bbfb",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.core.llama_pack import download_llama_pack\n",
    "\n",
    "download_llama_pack(\"SearChainPack\", \"./searchain_pack\")\n",
    "from searchain_pack.base import SearChainPack"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37739fc7-6df9-44e3-ac46-22471565af36",
   "metadata": {},
   "source": [
    "## Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d113b360-739e-4f29-b0db-273ba2d65e2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "searchain = SearChainPack(\n",
    "    data_path=\"data\",\n",
    "    dprtokenizer_path=\"./model/dpr_reader_multi\",\n",
    "    dprmodel_path=\"./model/dpr_reader_multi\",\n",
    "    crossencoder_name_or_path=\"./model/Quora_cross_encoder\",\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7a531d37-6832-40ab-b579-8dc007e1a1e2",
   "metadata": {},
   "source": [
    "## Excute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4dd90f1c-720a-4ef0-9a35-d1b54be8cd53",
   "metadata": {},
   "outputs": [],
   "source": [
    "start_idx = 0\n",
    "while not start_idx == -1:\n",
    "    start_idx = execute(\n",
    "        \"/hotpotqa/hotpot_dev_fullwiki_v1_line.json\", start_idx=start_idx\n",
    "    )"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
